Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
Getting a red squiglly line under the first cards[0], I dont know what is causing it

this is minimal js, everything else is commented. I cannot understand why "cards[i]"(first one in the for loop) has a red squiggly line under it, I cannot run any console commands. Please help!

    let cards=document.querySelectorAll(".blocks");
    let pic,card,rand;
    let finals = [];
    const count = 10; 
    const max = 9;
    
    for(let k = 0; k < 1000; k++){
      rand = Math.round(Math.random() * max);
    //   !finals.includes(rand) && finals.push(rand)
      if(!finals.includes(rand))
      finals.push(rand);
    }
    finals = finals.slice(0, count)
    setupCards(finals);
    
    function setupCards(arr){
        
        for(let i=0;i<=arr.length;i++){
    ====>cards[i].style.backgroundImage=`url(images/${arr[i]}.jpg)`;
        // cards[i].style.transform="rotateY(180deg)";
        // cards[i].style.backgroundImage="url(images/back6.jpg)";             
     }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In this condition test:

for(let i=0;i<=arr.length;i++){

you are letting the i go from zero (which is the index of the first element) to the length of the array (which gets you to the last plus 1 element - which doesn't exist).

Try:

  for(let i=0;i<arr.length;i++){
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda